const {ccclass, property} = cc._decorator;

/**回放的控制脚本 */
@ccclass
export default class ReplayCtrl extends cc.Component {

    /**回放的 播放、暂停、返回大厅按钮的容器 */
    replay: cc.Node = null;

    /**是否在播放中 */
    isPlaying = true;

    /**播放的剩余时间(单位：秒) */
    nextPlayTime = 1;

    onLoad() {
        if(!cc.vv){
            return;
        }

        this.replay = cc.find('Canvas/replay');
        this.replay.active = cc.vv.replayMgr.isReplay();    
    }

    /**暂停按钮的点击事件 */
    onBtnPauseClicked(){
        this.isPlaying = false;
    }

    /**播放按钮的点击事件 */
    onBtnPlayClicked(){
        this.isPlaying = true;
    }

    /**返回按钮的点击事件 */
    onBtnBackClicked(){
        cc.vv.replayMgr.clear();
        cc.vv.gameNetMgr.reset();
        cc.vv.wc.show('正在返回游戏大厅');
        cc.director.loadScene('hall');
    }

    update(dt: number){
        if(cc.vv){
            if(this.isPlaying && cc.vv.replayMgr.isReplay() == true){
                if(this.nextPlayTime > 0){
                    this.nextPlayTime -= dt;
                }
                else{
                    this.nextPlayTime = cc.vv.replayMgr.takeAction();
                }
            }
        }
    }
}
